public class Father {
    private String name;
    private Family family;
    public Father(String name){
        this.name = name;
    }

    public void setFamily(Family family) {
        this.family = family;
    }

    public void earning(double money) {
        synchronized (this.family){
            //查充值
            double leftMoney = this.family.getAccount();
            System.out.println("父亲"+this.name+"充值前余额"+leftMoney);
            this.family.setAccount(leftMoney + money);
            System.out.println("父亲"+this.name+" 充值后，家庭余额："+this.family.getAccount());
        }
    }
}
